<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="合同编号" prop="contractNo">
        <el-input
          v-model="queryParams.contract_no"
          placeholder="请输入合同编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="房源信息" prop="houseMessage">
        <el-input
          v-model="queryParams.houseMessage"
          placeholder="请输入房源信息"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="房东信息" prop="ownerMessage">
        <el-input
          v-model="queryParams.ownerMessage"
          placeholder="请输入房东信息"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="租户信息" prop="signUserMessage">
        <el-input
          v-model="queryParams.signUserMessage"
          placeholder="请输入租户信息"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="租约开始时间" prop="leaseStartTime">
        <el-date-picker clearable
                        v-model="queryParams.leaseStartTime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择租约期限开始时间"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="租约结束时间" prop="leaseEndTime">
        <el-date-picker clearable
                        v-model="queryParams.leaseEndTime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择租约期限结束时间"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="收房月租金" prop="monthRent">
        <el-input
          v-model="queryParams.monthRent"
          placeholder="请输入收房月租金"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="房产押金" prop="depositMoney">
        <el-input
          v-model="queryParams.depositMoney"
          placeholder="请输入房产押金"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="合同签订时间" prop="conSignTime">
        <el-date-picker clearable
                        v-model="queryParams.conSignTime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择合同签订时间"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['contract:contract:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['contract:contract:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['contract:contract:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="contractList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="主键id" align="center" prop="id"/>
      <el-table-column label="合同编号" align="center" prop="contractNo"/>
      <el-table-column label="上一合同ID" align="center" prop="lastContractId"/>
      <el-table-column label="商户ID" align="center" prop="businessId"/>
      <el-table-column label="部门ID" align="center" prop="deptId"/>
      <el-table-column label="部门编号" align="center" prop="deptNo"/>
      <el-table-column label="小区名(楼盘)" align="center" prop="premiseName"/>
      <el-table-column label="房源ID" align="center" prop="houseId"/>
      <el-table-column label="房源标题" align="center" prop="houseTitle"/>
      <el-table-column label="房东姓名" align="center" prop="ownerName"/>
      <el-table-column label="房东证件号码" align="center" prop="ownerIdCard"/>
      <el-table-column label="房东手机号" align="center" prop="ownerMobile"/>
      <el-table-column label="租户名称" align="center" prop="signUserName"/>
      <el-table-column label="租户证件号" align="center" prop="signUserCard"/>
      <el-table-column label="租户手机号" align="center" prop="signUserMobile"/>
      <el-table-column label="租户紧急联系电话" align="center" prop="signUserEmergencyPhone"/>
      <el-table-column label="租约期限开始时间" align="center" prop="leaseStartTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.leaseStartTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="租约期限结束时间" align="center" prop="leaseEndTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.leaseEndTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="月租金" align="center" prop="monthRent"/>
      <el-table-column label="房产押金" align="center" prop="depositMoney"/>
      <el-table-column label="合同签订时间" align="center" prop="conSignTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.conSignTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="合同录入时间" align="center" prop="conInfoTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.conInfoTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="合同审核时间" align="center" prop="conAudTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.conAudTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="合同录入人" align="center" prop="operId"/>
      <el-table-column label="合同状态" align="center" prop="status"/>
      <el-table-column label="备注" align="center" prop="remark"/>
      <el-table-column label="房产类型" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.houseLeaseType===1">合租</span>
          <span v-if="scope.row.houseLeaseType===2">整租</span>
          <span v-else>公寓</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['contract:contract:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['contract:contract:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      :page-sizes=[3,5,10,15,20]
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listContract, getContract, delContract, addContract, updateContract } from '@/api/contract/contract'

export default {
  name: 'Contract',
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      contractList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        contract_no: null,
        houseMessage: null,
        ownerMessage: null,
        signUserMessage: null,
        leaseStartTime: null,
        leaseEndTime: null,
        monthRent: null,
        depositMoney: null,
        conSignTime: null
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true
      listContract(this.queryParams).then(response => {
        this.contractList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        contractNo: null,
        lastContractId: null,
        businessId: null,
        deptId: null,
        deptNo: null,
        premiseName: null,
        houseId: null,
        houseTitle: null,
        ownerId: null,
        ownerName: null,
        ownerIdCard: null,
        ownerMobile: null,
        signUserName: null,
        signUserCard: null,
        signUserMobile: null,
        signUserEmergencyPhone: null,
        leaseStartTime: null,
        leaseEndTime: null,
        monthRent: null,
        depositMoney: null,
        conSignTime: null,
        conInfoTime: null,
        conAudTime: null,
        operId: null,
        status: 0,
        remark: null,
        houseLeaseType: null,
        createUserid: null,
        createTime: null,
        updateUserid: null,
        updateTime: null
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id
      this.$router.push( {path:'edit',query:{id:id}})

      // getContract(id).then(response => {
      //   this.form = response.data
      //   this.open = true
      //   this.title = '修改【请填写功能名称】'
      // })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除合同编号为"' + ids + '"的数据项？').then(function() {
        return delContract(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess('删除成功')
      }).catch(() => {
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('contract/contract/export', {
        ...this.queryParams
      }, `contract_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
